Density Map
Memory limit: 32 MB
There are given:
- integers ,
- - the table with the numbers from the set ; columns and lines of the table are numbered from to ; the number in -th column and -th line of the table is denoted by .
If
and
are two positions in the table
, the distance between them is
.
The table , , should be computed, where (the number in -th column and -th line of the table ) is equal to the sum of all the numbers , such that the distance between and is not greater than .
Task
Write a program, which:
- reads integers , and the table from the standard input,
- computes the table ,
- writes the table to the standard output.
Input
In the first line of standard input there are two positive integers separated by a single space: and , where . In the following lines the table is described. Each of these lines contains integers from the set , separated by single spaces. The -th number written in -st line is equal to .
Output
The standard output should contain exactly lines. In the -th line the values should be written respectively; they should be separated by single spaces.
Example
For the input data:
5 1
1 0 0 0 1
1 1 1 0 0
1 0 0 0 0
0 0 0 1 1
0 1 0 0 0
the correct result is:
3 4 2 2 1
4 5 2 2 1
3 4 3 3 2
2 2 2 2 2
1 1 2 2 2
Task author: Tomasz Smigielski.